#include "Adafruit_ST77xx.h"
#include <sys/_stdint.h>

#include "st7735s.h"

#if defined(ARDUINO_RASPBERRY_PI_PICO_W)
#define TFT_SCL 6 //18  //CLK 6
#define TFT_SDA 7 //19  //MOSI 7 DI
#define TFT_RST 3 //21  //RESET 5
#define TFT_DC  10 //20   //DC 6
#define TFT_CS  5 //17   //CS 5
//#define MIS0  4 //DO
#elif defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_IDF_TARGET_ESP32S3)
#define TFT_SCL 40  //CLK 6
#define TFT_SDA 21  //MOSI 7 DI
#define TFT_RST 41  //RESET 5
#define TFT_DC  16   //DC 6
#define TFT_CS  10   //CS 5
//#define MIS0  4 //DO
#else //STM32F103C8T6

#endif

Display::Display(){
    st7735 = new Adafruit_ST7735(TFT_CS,TFT_DC,TFT_SDA,TFT_SCL,TFT_RST);
    st7735->initR(INITR_BLACKTAB);
    st7735->setRotation(3);
    st7735->setTextWrap(false);
}

Display:: ~ Display(){

}
void Display::clear(){
    st7735->fillScreen(ST77XX_BLACK);
}
void Display::clear(uint16_t x,uint16_t y,int16_t w,int16_t h){
    st7735->fillRect(x, y, w, h, ST77XX_BLACK);
}

void Display::println(uint16_t x,uint16_t y,uint8_t size,uint16_t color,const char* text){
    st7735->setCursor(x,y);
    st7735->setTextColor(color);
    if(!strcmp(text,"auto")){
       st7735->setTextSize(1);
    }else{
      st7735->setTextSize(size);
    }
    st7735->println(text);
}

void Display::println(uint16_t x,uint16_t y,uint8_t size,const char* text){
    st7735->setCursor(x,y);
    st7735->setTextColor(ST77XX_GREEN);
    st7735->setTextSize(size);
    st7735->println(text);
}
